<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="代码" prop="CCE">
        <el-input
          v-model="queryParams.CCE"
          placeholder="请输入代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="名称" prop="DES">
        <el-input
          v-model="queryParams.DES"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="YSTA">
        <el-select v-model="queryParams.YSTA" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.x3_1003"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="备注" prop="YBZ">
        <el-input
          v-model="queryParams.YBZ"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话" prop="YDH">
        <el-input
          v-model="queryParams.YDH"
          placeholder="请输入电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证" prop="YSFZ">
        <el-input
          v-model="queryParams.YSFZ"
          placeholder="请输入身份证"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="在职" prop="YZZ">
        <el-select v-model="queryParams.YZZ" placeholder="请选择在职" clearable>
          <el-option
            v-for="dict in dict.type.x3_1"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="ERP编号" prop="YERPBH">
        <el-input
          v-model="queryParams.YERPBH"
          placeholder="请输入ERP编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="一级办事处" prop="YYJBM">
        <el-input
          v-model="queryParams.YYJBM"
          placeholder="请输入一级办事处"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="二级办事处" prop="YEJBM">
        <el-input
          v-model="queryParams.YEJBM"
          placeholder="请输入二级办事处"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="三级办事处" prop="YRYSJBM">
        <el-input
          v-model="queryParams.YRYSJBM"
          placeholder="请输入三级办事处"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['x3base:gescce4:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['x3base:gescce4:remove']"
        >删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="gescce4List" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="代码" align="center" prop="CCE" />
      <el-table-column label="名称" align="center" prop="DES" />
      <el-table-column label="状态" align="center" prop="YSTA">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.x3_1003" :value="scope.row.YSTA"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="YBZ" />
      <el-table-column label="交易对象" align="center" prop="YJYDX" />
      <el-table-column label="性别" align="center" prop="YXB">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.x3_1004" :value="scope.row.YXB"/>
        </template>
      </el-table-column>
      <el-table-column label="电话" align="center" prop="YDH" />
      <el-table-column label="身份证" align="center" prop="YSFZ" />
      <el-table-column label="入职日期" align="center" prop="YRZDAT" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.YRZDAT }}</span>
        </template>
      </el-table-column>
      <el-table-column label="离职日期" align="center" prop="YLZDAT" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.YLZDAT }}</span>
        </template>
      </el-table-column>
      <el-table-column label="在职" align="center" prop="YZZ">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.x3_1" :value="scope.row.YZZ"/>
        </template>
      </el-table-column>
      <el-table-column label="在职时间" align="center" prop="YZZSJ" />
      <el-table-column label="ERP编号" align="center" prop="YERPBH" />
      <el-table-column label="岗位" align="center" prop="YGW" />
      <el-table-column label="产品中心" align="center" prop="YCPZX" />
      <el-table-column label="岗位类型" align="center" prop="YGWLX" />
      <el-table-column label="PDA编号" align="center" prop="YPDA" />
      <el-table-column label="营养顾问供货方" align="center" prop="YGHF" />
      <el-table-column label="归属商务经理" align="center" prop="YSWJL" />
      <el-table-column label="市场专员" align="center" prop="YSCZY" />
      <el-table-column label="是否参与心动项目" align="center" prop="YXM">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.x3_1" :value="scope.row.YXM"/>
        </template>
      </el-table-column>
      <el-table-column label="提成方式" align="center" prop="YTC" />
      <el-table-column label="公司承担社保" align="center" prop="YSBGS" />
      <el-table-column label="公司承担公积金" align="center" prop="YGJJGS" />
      <el-table-column label="个人承担社保" align="center" prop="YSBGR" />
      <el-table-column label="个人承担公积金" align="center" prop="YGJJGR" />
      <el-table-column label="银行账号" align="center" prop="YYHZH" />
      <el-table-column label="开户银行全称" align="center" prop="YYHMC" />
      <el-table-column label="开户行所在省" align="center" prop="YKHS" />
      <el-table-column label="开户行所在市" align="center" prop="YKHSZS" />
      <el-table-column label="省" align="center" prop="YS" />
      <el-table-column label="市" align="center" prop="YSHI" />
      <el-table-column label="区/县" align="center" prop="YX" />
      <el-table-column label="乡镇" align="center" prop="YZ" />
      <el-table-column label="直属员工" align="center" prop="YZSYG" />
      <el-table-column label="代付客户" align="center" prop="YDFKH" />
      <el-table-column label="通路" align="center" prop="YTL" />
      <el-table-column label="归属" align="center" prop="YGS" />
      <el-table-column label="生日" align="center" prop="YSR" />
      <el-table-column label="学历" align="center" prop="YXL" />
      <el-table-column label="血型" align="center" prop="YXX" />
      <el-table-column label="所属事业部" align="center" prop="YSYB" />
      <el-table-column label="面试评分" align="center" prop="YPF" />
      <el-table-column label="试岗考核" align="center" prop="YSGKH" />
      <el-table-column label="一级办事处" align="center" prop="YYJBM" />
      <el-table-column label="一级办事处名称" align="center" prop="ZYYJBM" />
      <el-table-column label="二级办事处" align="center" prop="YEJBM" />
      <el-table-column label="二级办事处名称" align="center" prop="ZYEJBM" />
      <el-table-column label="三级办事处" align="center" prop="YRYSJBM" />
      <el-table-column label="三级办事处名称" align="center" prop="ZYRYSJBM" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['x3base:gescce:edit']" v-if="scope.row.YSTA<=1">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['x3base:gescce:remove']" v-if="scope.row.YSTA<=1">删除</el-button>
          <el-button size="mini" type="text" @click="handle('a',scope.row)" v-if="scope.row.YSTA==1">审核</el-button>
          <el-button size="mini" type="text" @click="handle('b',scope.row)" v-if="scope.row.YSTA==2">停用</el-button>
          <el-button size="mini" type="text" @click="handle('c',scope.row)" v-if="scope.row.YSTA==2">驳回</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改人员信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="代码" prop="CCE">
          <el-input v-model="form.CCE" placeholder="请输入代码" />
        </el-form-item>
        <el-form-item label="名称" prop="DES">
          <el-input v-model="form.DES" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="备注" prop="YBZ">
          <el-input v-model="form.YBZ" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="交易对象" prop="YJYDX">
          <el-input v-model="form.YJYDX" placeholder="请输入交易对象" />
        </el-form-item>
        <el-form-item label="性别" prop="YXB">
          <el-select v-model="form.YXB" placeholder="请选择性别">
            <el-option
              v-for="dict in dict.type.x3_1004"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="电话" prop="YDH">
          <el-input v-model="form.YDH" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="身份证" prop="YSFZ">
          <el-input v-model="form.YSFZ" placeholder="请输入身份证" />
        </el-form-item>
        <el-form-item label="入职日期" prop="YRZDAT">
          <el-date-picker clearable
                          v-model="form.YRZDAT"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择入职日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="离职日期" prop="YLZDAT">
          <el-date-picker clearable
                          v-model="form.YLZDAT"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择离职日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="在职" prop="YZZ">
          <el-select v-model="form.YZZ" placeholder="请选择在职">
            <el-option
              v-for="dict in dict.type.x3_1"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="在职时间" prop="YZZSJ">
          <el-input v-model="form.YZZSJ" placeholder="请输入在职时间" />
        </el-form-item>
        <el-form-item label="ERP编号" prop="YERPBH">
          <el-input v-model="form.YERPBH" placeholder="请输入ERP编号" />
        </el-form-item>
        <el-form-item label="岗位" prop="YGW">
          <el-input v-model="form.YGW" placeholder="请输入岗位" />
        </el-form-item>
        <el-form-item label="产品中心" prop="YCPZX">
          <el-input v-model="form.YCPZX" placeholder="请输入产品中心" />
        </el-form-item>
        <el-form-item label="岗位类型" prop="YGWLX">
          <el-input v-model="form.YGWLX" placeholder="请输入岗位类型" />
        </el-form-item>
        <el-form-item label="PDA编号" prop="YPDA">
          <el-input v-model="form.YPDA" placeholder="请输入PDA编号" />
        </el-form-item>
        <el-form-item label="营养顾问供货方" prop="YGHF">
          <el-input v-model="form.YGHF" placeholder="请输入营养顾问供货方" />
        </el-form-item>
        <el-form-item label="归属商务经理" prop="YSWJL">
          <el-input v-model="form.YSWJL" placeholder="请输入归属商务经理" />
        </el-form-item>
        <el-form-item label="市场专员" prop="YSCZY">
          <el-input v-model="form.YSCZY" placeholder="请输入市场专员" />
        </el-form-item>
        <el-form-item label="是否参与心动项目" prop="YXM">
          <el-select v-model="form.YXM" placeholder="请选择是否参与心动项目">
            <el-option
              v-for="dict in dict.type.x3_1"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="提成方式" prop="YTC">
          <el-input v-model="form.YTC" placeholder="请输入提成方式" />
        </el-form-item>
        <el-form-item label="公司承担社保" prop="YSBGS">
          <el-input v-model="form.YSBGS" placeholder="请输入公司承担社保" />
        </el-form-item>
        <el-form-item label="公司承担公积金" prop="YGJJGS">
          <el-input v-model="form.YGJJGS" placeholder="请输入公司承担公积金" />
        </el-form-item>
        <el-form-item label="个人承担社保" prop="YSBGR">
          <el-input v-model="form.YSBGR" placeholder="请输入个人承担社保" />
        </el-form-item>
        <el-form-item label="个人承担公积金" prop="YGJJGR">
          <el-input v-model="form.YGJJGR" placeholder="请输入个人承担公积金" />
        </el-form-item>
        <el-form-item label="银行账号" prop="YYHZH">
          <el-input v-model="form.YYHZH" placeholder="请输入银行账号" />
        </el-form-item>
        <el-form-item label="开户银行全称" prop="YYHMC">
          <el-input v-model="form.YYHMC" placeholder="请输入开户银行全称" />
        </el-form-item>
        <el-form-item label="开户行所在省" prop="YKHS">
          <el-input v-model="form.YKHS" placeholder="请输入开户行所在省" />
        </el-form-item>
        <el-form-item label="开户行所在市" prop="YKHSZS">
          <el-input v-model="form.YKHSZS" placeholder="请输入开户行所在市" />
        </el-form-item>
        <el-form-item label="省" prop="YS">
          <el-input v-model="form.YS" placeholder="请输入省" />
        </el-form-item>
        <el-form-item label="市" prop="YSHI">
          <el-input v-model="form.YSHI" placeholder="请输入市" />
        </el-form-item>
        <el-form-item label="区/县" prop="YX">
          <el-input v-model="form.YX" placeholder="请输入区/县" />
        </el-form-item>
        <el-form-item label="乡镇" prop="YZ">
          <el-input v-model="form.YZ" placeholder="请输入乡镇" />
        </el-form-item>
        <el-form-item label="直属员工" prop="YZSYG">
          <el-input v-model="form.YZSYG" placeholder="请输入直属员工" />
        </el-form-item>
        <el-form-item label="代付客户" prop="YDFKH">
          <el-input v-model="form.YDFKH" placeholder="请输入代付客户" />
        </el-form-item>
        <el-form-item label="通路" prop="YTL">
          <el-input v-model="form.YTL" placeholder="请输入通路" />
        </el-form-item>
        <el-form-item label="归属" prop="YGS">
          <el-input v-model="form.YGS" placeholder="请输入归属" />
        </el-form-item>
        <el-form-item label="生日" prop="YSR">
          <el-input v-model="form.YSR" placeholder="请输入生日" />
        </el-form-item>
        <el-form-item label="学历" prop="YXL">
          <el-input v-model="form.YXL" placeholder="请输入学历" />
        </el-form-item>
        <el-form-item label="血型" prop="YXX">
          <el-input v-model="form.YXX" placeholder="请输入血型" />
        </el-form-item>
        <el-form-item label="所属事业部" prop="YSYB">
          <el-input v-model="form.YSYB" placeholder="请输入所属事业部" />
        </el-form-item>
        <el-form-item label="面试评分" prop="YPF">
          <el-input v-model="form.YPF" placeholder="请输入面试评分" />
        </el-form-item>
        <el-form-item label="试岗考核" prop="YSGKH">
          <el-input v-model="form.YSGKH" placeholder="请输入试岗考核" />
        </el-form-item>
        <el-form-item label="一级办事处" prop="YYJBM">
          <el-input v-model="form.YYJBM" placeholder="请输入一级办事处" />
        </el-form-item>
        <el-form-item label="一级办事处名称" prop="ZYYJBM">
          <el-input v-model="form.ZYYJBM" placeholder="请输入一级办事处名称" />
        </el-form-item>
        <el-form-item label="二级办事处" prop="YEJBM">
          <el-input v-model="form.YEJBM" placeholder="请输入二级办事处" />
        </el-form-item>
        <el-form-item label="二级办事处名称" prop="ZYEJBM">
          <el-input v-model="form.ZYEJBM" placeholder="请输入二级办事处名称" />
        </el-form-item>
        <el-form-item label="三级办事处" prop="YRYSJBM">
          <el-input v-model="form.YRYSJBM" placeholder="请输入三级办事处" />
        </el-form-item>
        <el-form-item label="三级办事处名称" prop="ZYRYSJBM">
          <el-input v-model="form.ZYRYSJBM" placeholder="请输入三级办事处名称" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listGescce4, getGescce4, delGescce4, addGescce4, updateGescce4 } from "@/api/x3base/gescce4";
import {actionGescce} from "@/api/x3base/gescce3";

export default {
  name: "Gescce4",
  dicts: ['x3_1', 'x3_1003', 'x3_1004'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 人员信息表格数据
      gescce4List: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        CCE: null,
        DES: null,
        YSTA: null,
        YBZ: null,
        YDH: null,
        YSFZ: null,
        YZZ: null,
        YERPBH: null,
        YYJBM: null,
        YEJBM: null,
        YRYSJBM: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      isAdd:false
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询人员信息列表 */
    getList() {
      this.loading = true;
      listGescce4(this.queryParams).then(response => {
        this.gescce4List = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        CCE: null,
        DES: null,
        YSTA: null,
        YBZ: null,
        CREDAT: null,
        YSHDATA: null,
        YJYDX: null,
        YXB: null,
        YDH: null,
        YSFZ: null,
        YRZDAT: null,
        YLZDAT: null,
        YZZ: null,
        YZZSJ: null,
        YERPBH: null,
        YGW: null,
        YCPZX: null,
        YGWLX: null,
        YPDA: null,
        YGHF: null,
        YSWJL: null,
        YSCZY: null,
        YXM: null,
        YTC: null,
        YSBGS: null,
        YGJJGS: null,
        YSBGR: null,
        YGJJGR: null,
        YYHZH: null,
        YYHMC: null,
        YKHS: null,
        YKHSZS: null,
        YS: null,
        YSHI: null,
        YX: null,
        YZ: null,
        YZSYG: null,
        YDFKH: null,
        YTL: null,
        YGS: null,
        YSR: null,
        YXL: null,
        YXX: null,
        YSYB: null,
        YPF: null,
        YSGKH: null,
        YYJBM: null,
        ZYYJBM: null,
        YEJBM: null,
        ZYEJBM: null,
        YRYSJBM: null,
        ZYRYSJBM: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.CCE)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加人员信息";
      this.isAdd=true
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const CCE = row.CCE || this.ids
      this.isAdd=false
      getGescce4(CCE).then(response => {
        this.form = response.data["HEAD"];
        this.open = true;
        this.title = "修改人员信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.isAdd != true) {
            updateGescce4(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGescce4(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const CCEs = row.CCE || this.ids;
      this.$modal.confirm('是否确认删除人员信息编号为"' + CCEs + '"的数据项？').then(function() {
        return delGescce4(CCEs);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('x3base/gescce4/export', {
        ...this.queryParams
      }, `gescce4_${new Date().getTime()}.xlsx`)
    },
    /** 修改按钮操作 */
    handle(flag,row) {
      actionGescce(row,flag).then(response => {
        this.$modal.msgSuccess("操作成功");
        this.open = false;
        this.getList();
      });
    },
  }
};
</script>
